package com.yang.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.yang.entity.PhoneBook;
import com.yang.util.DBHelp;
import com.yang.util.MapRow;

public class PhoneBookDao {

	private DBHelp<PhoneBook> dh=new DBHelp<PhoneBook>();

	public List<PhoneBook> findByGroupIdAndUserId(String userid, String groupid) {
		String sql="select * from t_phonebook where userid=? and groupid=?";
		MapRow<PhoneBook> mr=new Mr();
		return dh.findList(sql, mr, userid,groupid);
	}
	private class Mr implements MapRow<PhoneBook>{

		@Override
		public PhoneBook RowMap(ResultSet rs) throws SQLException {
			PhoneBook pb=new PhoneBook();
			pb.setCode(rs.getString("code"));
			pb.setGroupid(rs.getString("groupid"));
			pb.setId(rs.getString("id"));
			pb.setName(rs.getString("name"));
			pb.setOthername(rs.getString("othername"));
			pb.setUserid(rs.getString("userid"));
			return pb;
		}
		
	}
	public boolean insertRole(String roleid, String userid, String groupid) {
		String sql="insert into t_role(id,groupid,userid,otherid)values(?,?,?,?)";
		return dh.add(sql, roleid,groupid,userid,"");
	}
	public boolean insertPB(String pbid, String name, String code,
			String userid, String groupid, String othername) {
		String sql="insert into t_phonebook(id,name,code,userid,groupid,othername)values(?,?,?,?,?,?)";
		return dh.add(sql, pbid,name,code,userid,groupid,othername);
	}
}
